<template>
	<view class="login-container">
		<!-- 顶部logo区域 -->
		<view class="logo-section">
			<image class="logo-img" :src="logoSrc" mode="aspectFit"></image>
			<text class="app-name">舞动智韵</text>
			<text class="app-slogan">让舞蹈成为生活的艺术</text>
		</view>
		
		<!-- 登录注册切换 -->
		<view class="tab-section">
			<view class="tab-item" :class="{active: currentTab === 'login'}" @tap="switchTab('login')">
				<text class="tab-text">登录</text>
			</view>
			<view class="tab-item" :class="{active: currentTab === 'register'}" @tap="switchTab('register')">
				<text class="tab-text">注册</text>
			</view>
		</view>
		
		<!-- 表单区域 -->
		<view class="form-section">
			<!-- 登录表单 -->
			<view v-if="currentTab === 'login'" class="form-container">
				<view class="input-group">
					<view class="input-item">
						<text class="input-icon">📱</text>
						<input class="input-field" type="text" placeholder="请输入手机号" v-model="loginForm.phone" />
					</view>
					<view class="input-item">
						<text class="input-icon">🔒</text>
						<input class="input-field" type="password" placeholder="请输入密码" v-model="loginForm.password" />
					</view>
				</view>
				
				<view class="forgot-password" @tap="forgotPassword">
					<text class="forgot-text">忘记密码？</text>
				</view>
				
				<button class="submit-btn" @tap="handleLogin">登录</button>
			</view>
			
			<!-- 注册表单 -->
			<view v-else class="form-container">
				<view class="input-group">
					<view class="input-item">
						<text class="input-icon">👤</text>
						<input class="input-field" type="text" placeholder="请输入用户名" v-model="registerForm.username" />
					</view>
					<view class="input-item">
						<text class="input-icon">📱</text>
						<input class="input-field" type="text" placeholder="请输入手机号" v-model="registerForm.phone" />
					</view>
					<view class="input-item">
						<text class="input-icon">🔒</text>
						<input class="input-field" type="password" placeholder="请输入密码" v-model="registerForm.password" />
					</view>
					<view class="input-item">
						<text class="input-icon">🔒</text>
						<input class="input-field" type="password" placeholder="确认密码" v-model="registerForm.confirmPassword" />
					</view>
				</view>
				
				<view class="agreement-section">
					<view class="agreement-item" @tap="toggleAgreement">
						<text class="checkbox" :class="{checked: isAgreed}">{{isAgreed ? '✓' : ''}}</text>
						<text class="agreement-text">我已阅读并同意</text>
						<text class="agreement-link" @tap.stop="showAgreement">《用户协议》</text>
					</view>
				</view>
				
				<button class="submit-btn" @tap="handleRegister">注册</button>
			</view>
		</view>
		
		<!-- 其他登录方式 -->
		<view class="other-login">
			<view class="divider">
				<text class="divider-text">其他登录方式</text>
			</view>
			<view class="social-login">
				<view class="social-item" @tap="wechatLogin">
					<text class="social-icon">💬</text>
					<text class="social-text">微信登录</text>
				</view>
				<view class="social-item" @tap="qqLogin">
					<text class="social-icon">🐧</text>
					<text class="social-text">QQ登录</text>
				</view>
			</view>
		</view>
		
		<!-- 游客模式 -->
		<view class="guest-mode">
			<text class="guest-text" @tap="guestLogin">游客模式体验</text>
		</view>
	</view>
</template>

<script>
import auth from '../../utils/auth.js'

export default {
	name: 'Login',
	data() {
		return {
			logoSrc: require('../../static/bg-logo.png'),
			currentTab: 'login', // 'login' 或 'register'
			isAgreed: false,
			loginForm: {
				phone: '',
				password: ''
			},
			registerForm: {
				username: '',
				phone: '',
				password: '',
				confirmPassword: ''
			}
		}
	},
	methods: {
		switchTab(tab) {
			this.currentTab = tab;
		},
		handleLogin() {
			if (!this.loginForm.phone) {
				uni.showToast({
					title: '请输入手机号',
					icon: 'none'
				});
				return;
			}
			if (!this.loginForm.password) {
				uni.showToast({
					title: '请输入密码',
					icon: 'none'
				});
				return;
			}
			
			// 模拟登录成功，保存用户信息
			const userInfo = {
				phone: this.loginForm.phone,
				username: 'Yaqi Yang',
				level: '高级会员'
			};
			
			auth.setLoginStatus(userInfo);
			
			uni.showToast({
				title: '登录成功',
				icon: 'success'
			});
			
			// 跳转到首页
			setTimeout(() => {
				uni.reLaunch({
					url: '/pages/home/home'
				});
			}, 1500);
		},
		handleRegister() {
			if (!this.registerForm.username) {
				uni.showToast({
					title: '请输入用户名',
					icon: 'none'
				});
				return;
			}
			if (!this.registerForm.phone) {
				uni.showToast({
					title: '请输入手机号',
					icon: 'none'
				});
				return;
			}
			if (!this.registerForm.password) {
				uni.showToast({
					title: '请输入密码',
					icon: 'none'
				});
				return;
			}
			if (this.registerForm.password !== this.registerForm.confirmPassword) {
				uni.showToast({
					title: '两次密码不一致',
					icon: 'none'
				});
				return;
			}
			if (!this.isAgreed) {
				uni.showToast({
					title: '请先同意用户协议',
					icon: 'none'
				});
				return;
			}
			
			// 模拟注册成功
			uni.showToast({
				title: '注册成功',
				icon: 'success'
			});
			
			// 自动切换到登录
			setTimeout(() => {
				this.currentTab = 'login';
				this.loginForm.phone = this.registerForm.phone;
			}, 1500);
		},
		toggleAgreement() {
			this.isAgreed = !this.isAgreed;
		},
		showAgreement() {
			uni.showModal({
				title: '用户协议',
				content: '这里是用户协议的内容...',
				showCancel: false
			});
		},
		forgotPassword() {
			uni.showToast({
				title: '请联系客服找回密码',
				icon: 'none'
			});
		},
		wechatLogin() {
			uni.showToast({
				title: '微信登录功能开发中',
				icon: 'none'
			});
		},
		qqLogin() {
			uni.showToast({
				title: 'QQ登录功能开发中',
				icon: 'none'
			});
		},
		guestLogin() {
			// 游客模式也设置一个临时用户状态
			const guestInfo = {
				phone: '游客',
				username: '游客用户',
				level: '游客'
			};
			
			auth.setLoginStatus(guestInfo);
			
			uni.showToast({
				title: '进入游客模式',
				icon: 'success'
			});
			
			setTimeout(() => {
				uni.reLaunch({
					url: '/pages/home/home'
				});
			}, 1000);
		}
	}
}
</script>

<style scoped>
.login-container {
	min-height: 100vh;
	background: linear-gradient(135deg, #FFE4E6 0%, #FFF0F2 100%);
	padding: 60rpx 40rpx 40rpx;
	display: flex;
	flex-direction: column;
}

.logo-section {
	display: flex;
	flex-direction: column;
	align-items: center;
	margin-bottom: 80rpx;
	padding-top: 60rpx;
}

.logo-img {
	width: 120rpx;
	height: 120rpx;
	margin-bottom: 30rpx;
}

.app-name {
	font-size: 48rpx;
	font-weight: bold;
	color: #333333;
	margin-bottom: 10rpx;
}

.app-slogan {
	font-size: 24rpx;
	color: #999999;
}

.tab-section {
	display: flex;
	background: #FFFFFF;
	border-radius: 30rpx;
	padding: 8rpx;
	margin-bottom: 60rpx;
	box-shadow: 0 4rpx 20rpx rgba(255, 107, 157, 0.1);
}

.tab-item {
	flex: 1;
	text-align: center;
	padding: 24rpx 0;
	border-radius: 24rpx;
	transition: all 0.3s ease;
}

.tab-item.active {
	background: #FF6B9D;
}

.tab-text {
	font-size: 28rpx;
	color: #666666;
	font-weight: 500;
}

.tab-item.active .tab-text {
	color: #FFFFFF;
	font-weight: bold;
}

.form-section {
	flex: 1;
	margin-bottom: 40rpx;
}

.form-container {
	background: #FFFFFF;
	border-radius: 30rpx;
	padding: 50rpx 40rpx;
	box-shadow: 0 4rpx 20rpx rgba(255, 107, 157, 0.1);
}

.input-group {
	margin-bottom: 40rpx;
}

.input-item {
	display: flex;
	align-items: center;
	padding: 30rpx 0;
	border-bottom: 2rpx solid #F5F5F5;
	margin-bottom: 20rpx;
}

.input-item:last-child {
	margin-bottom: 0;
}

.input-icon {
	font-size: 32rpx;
	margin-right: 20rpx;
	width: 40rpx;
}

.input-field {
	flex: 1;
	font-size: 28rpx;
	color: #333333;
}

.forgot-password {
	text-align: right;
	margin-bottom: 40rpx;
}

.forgot-text {
	font-size: 24rpx;
	color: #FF6B9D;
}

.agreement-section {
	margin-bottom: 40rpx;
}

.agreement-item {
	display: flex;
	align-items: center;
}

.checkbox {
	width: 32rpx;
	height: 32rpx;
	border: 2rpx solid #CCCCCC;
	border-radius: 6rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 20rpx;
	margin-right: 15rpx;
	color: #FFFFFF;
}

.checkbox.checked {
	background: #FF6B9D;
	border-color: #FF6B9D;
}

.agreement-text {
	font-size: 24rpx;
	color: #666666;
	margin-right: 10rpx;
}

.agreement-link {
	font-size: 24rpx;
	color: #FF6B9D;
}

.submit-btn {
	width: 100%;
	background: #FF6B9D;
	color: #FFFFFF;
	border: none;
	border-radius: 30rpx;
	padding: 30rpx 0;
	font-size: 32rpx;
	font-weight: bold;
	transition: all 0.3s ease;
}

.submit-btn:active {
	transform: scale(0.98);
	background: #E85A87;
}

.other-login {
	margin-bottom: 40rpx;
}

.divider {
	display: flex;
	align-items: center;
	margin-bottom: 40rpx;
}

.divider::before,
.divider::after {
	content: '';
	flex: 1;
	height: 2rpx;
	background: #E5E5E5;
}

.divider-text {
	font-size: 24rpx;
	color: #999999;
	margin: 0 30rpx;
}

.social-login {
	display: flex;
	justify-content: center;
	gap: 60rpx;
}

.social-item {
	display: flex;
	flex-direction: column;
	align-items: center;
	padding: 20rpx;
}

.social-icon {
	font-size: 48rpx;
	margin-bottom: 15rpx;
}

.social-text {
	font-size: 22rpx;
	color: #666666;
}

.guest-mode {
	text-align: center;
}

.guest-text {
	font-size: 26rpx;
	color: #999999;
	padding: 20rpx;
	border-bottom: 2rpx solid #CCCCCC;
}
</style> 